package com.atguigu.msmservice.service.impl;

import com.atguigu.msmservice.service.MsmService;
import com.zhenzi.sms.ZhenziSmsClient;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MsmServiceImpl implements MsmService {
    //发送短信的方法
    @Override
    public boolean sendMsm(String code, String phone) {
        try {
            final String apiUrl="https://sms_developer.zhenzikj.com";
            final String appId="110264";
            final String appSecret="381973e8-ee2b-46b6-a78c-51f2c33623d0";
            ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("number", phone);
            params.put("templateId", "7145");
            String[] templateParams = new String[2];
            templateParams[0] = code;
            templateParams[1] = "5分钟";
            params.put("templateParams", templateParams);
            String result = client.send(params);
            System.out.println(result);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
